package com.webAutoTest.CommonDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;

import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description:创建驱动对象并返回
 * User: lenovo
 * Date: 2023-01-18
 * Time: 18:20
 */
public class CommomDriver {
    private static ChromeDriver driver = null;//static静态,变量全局只有一份
    public static ChromeDriver getDriver(){
        if (driver == null){
            driver = new ChromeDriver();
//            //添加隐式等待
//            driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        }
        return driver;
    }

    //登录
    public static void login(){
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        driver.get("http://101.33.234.81:8080/blog_system/login.html");

        String wind1 = driver.getWindowHandle();
        System.out.println(wind1);
        //selenium定位元素
        driver.findElement(By.cssSelector("#username")).sendKeys("lisi");
        driver.findElement(By.cssSelector("#password")).sendKeys("123");
        driver.findElement(By.xpath("//*[@id=\"login-btn\"]")).click();
//        String url1 = driver.getCurrentUrl();
//        System.out.println(url1);
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

//        driver.get("http://101.33.234.81:8080/blog_system/blog_list.html");
//        driver.findElement(By.cssSelector("body > div.container > div.container-right > div:nth-child(1) > a"));
//       String url2 = driver.getCurrentUrl();
//        System.out.println(url2);
        String wind2 = driver.getWindowHandle();
        System.out.println(wind2);
        /**
         * 是同一个窗口
         */
    }




}
